package com.snail.billing.session;

import com.snail.billing.DataCache;
import com.snail.billing.data.Account;
import com.snail.billing.data.AccountManager;
import com.snail.billing.net.BillingEncode;
import com.snail.billing.net.BillingSecurity;
import com.snail.billing.net.BillingTreeArrayHttpSession;

public class BindAccountSession extends BillingTreeArrayHttpSession {

	public BindAccountSession(String account, String pwd) {
		DataCache cache = DataCache.getInstance();
		String host = cache.importParams.hostSecurity;
		BillingSecurity security = getSecurity();
		String address = String.format("http://%s/api/%s/%s/bindaliase", host, security.accessId, security.accessType);
		setAddress(address);
		Account curAccount = AccountManager.getCurrentAccount();
		addBillingPair("account", curAccount.getAccount());
		addBillingPair("oldPwd", BillingEncode.MD5(curAccount.getPwd()));
		addBillingPair("aliase", account);
		addBillingPair("newPwd", BillingEncode.enCode(pwd, "UTF-8"));
		buildParamPair();
	}

	@Override
	public BillingSecurity getSecurity() {
		if (DataCache.getInstance().isSandbox) {
			return BillingSecurity.securitySandbox2;
		}
		return BillingSecurity.security;
	}
}